package com.jsb.laundry.enums;

import com.jsb.laundry.service.designpatterns.adapter.loginservice.LoginAdapter;
import com.jsb.laundry.service.designpatterns.adapter.loginservice.impl.LoginForTelAdapter;
import com.jsb.laundry.service.designpatterns.adapter.loginservice.impl.LoginForWechatAdapter;

public enum LoginType {
    wx_mini_login("0", "微信小程序登录", LoginForWechatAdapter.class),
    user_phone_login("1", "手机号验证码登录", LoginForTelAdapter.class),
    ;
    private String code;
    private String name;
    private Class<? extends LoginAdapter> clazz;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Class getClazz() {
        return clazz;
    }

    public void setClazz(Class clazz) {
        this.clazz = clazz;
    }

    LoginType(String code, String name, Class clazz) {
        this.code = code;
        this.name = name;
        this.clazz = clazz;
    }

    /**
     * 查询枚举是否存在
     *
     * @param loginType
     * @return
     */
    public static Class<? extends LoginAdapter> containsLoginType(String loginType) {
        for (LoginType value : LoginType.values()) {
            if (value.name().equals(loginType)) {
                return value.getClazz();
            }
        }
        return null;
    }

    /**
     * 根据code找枚举名
     *
     * @param code
     * @return
     */
    public static String getNameById(String code) {
        for (LoginType value : values()) {
            if (value.getCode().equals(code)) {
                return value.name();
            }
        }
        return null;
    }


}
